<?php
	$logid=GetLoginUserID();
	if(isset($_GET['uid'])&&intval($_GET['uid'])>0)
	{
		$uid=intval($_GET['uid']);
	}
	else
	{
		if($logid!=false)
			$uid=$logid;
		else
			edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));
	}
	
	$userDAO=GetUserDAO();
	$user=$userDAO->GetUserNameByID($uid);
	if(!$user)
		edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));
	
	$friendDAO=GetFriendDAO();
	$friendCount=$friendDAO->GetFriendCountByUid($uid);
	/*
	 * memcached code here!
	 */
		
	//Get page num
	$page='1';
	if(isset($_GET['p'])&& is_numeric($_GET['p']) )
	{
		$page=intval($_GET['p']);
	}
		
	//Get sort type
	if(isset($_GET['sortby']))
	  $sortby=intval($_GET['sortby']);
	else 
	  $sortby = '1';
	  
	switch($sortby){

	   case '1':{	   	
	      $sortby_t = 'nick';
	      break;
	   }	   	
	   
	   case '2':{	   	
	      $sortby_t = 'contribution';
	      break;
	   }	   	   
	   default:{	 
	      $sortby_t = 'nick';
	      break;   	 	
	   }			   
	}
	
	
	//Get order type
	if(isset($_GET['order']))
		$order=intval($_GET['order']);
	else 
	 	$order = '1';
	switch($order){

	   case '1':{	   	
	      $order_t = 'asc';
	      break;
	   }	   	
	   
	   case '2':{	   	
	      $order_t = 'desc';
	      break;
	   }	   	   
	   default:{	 
	      $order_t = 'asc';
	      break;   	 	
	   }			   
	}
	
	$friendList=$friendDAO->GetFriendsByUid($uid, $sortby_t, $order_t, $page, '12');	

	
	$currentURL = htmlspecialchars( $_SERVER["REQUEST_URI"] );
	$currentURL = preg_replace( '/&p=[0-9]+/', "", $currentURL );
	/*
	 * Page bar
	 */
	require_once ( LIB_DIR.'classes/Pager.php' );
	$pageObj = new Pager($currentURL,
	$friendCount, '12', $page, UP_RESULT_PAGE );
	
?>
